package com.ithuaxin.method;

import java.util.Random;
import java.util.Scanner;

public class Test10 {
    public static void main(String[] args) {
        int number[] = getNumber();
        for (int i = 0; i < number.length; i++) {
            System.out.print(number[i] + " ");
        }
        System.out.println("");
        int userArr[] = userInputNumber();
        System.out.println("");
        for (int i = 0; i < userArr.length; i++) {
            System.out.print(userArr[i] + " ");
        }
        System.out.println("");
        int redCount = 0;
        int blueCount = 0;
        for (int i = 0; i < userArr.length-1; i++) {
            int redNumber = userArr[i];
            for (int j = 0; j < number.length-1; j++) {
                if (redNumber==number[j]){
                    redCount++;
                    break;
                }
            }
        }
        System.out.println("红球的中奖个数是："+redCount);
        int blueNumber = userArr[userArr.length-1];
        if (blueNumber==number[number.length-1]){
            blueCount++;
        }
        System.out.println("蓝球的中奖个数是："+blueCount);
        if (redCount==6&&blueCount==1){
            System.out.println("恭喜你中奖1000万元");
        }else if (redCount==6&&blueCount==0){
            System.out.println("恭喜你中奖500万元");
        }else if (redCount==5&&blueCount==1){
            System.out.println("恭喜你中奖3000元");
        }else if ((redCount==5&&blueCount==0)||(redCount==4&&blueCount==1)){
            System.out.println("恭喜你中奖200元");
        }else if ((redCount==4&&blueCount==0)||(redCount==3&&blueCount==1)){
            System.out.println("恭喜你中奖10元");
        }else if ((redCount==2&&blueCount==1)||(redCount==1&&blueCount==1)||(redCount==0&&blueCount==1)){
            System.out.println("恭喜你中奖5元");
        }else{
            System.out.println("谢谢参与，感谢您对福利彩票的支持");
        }

    }
    public static int[] getNumber(){
        int number[] = new int[7];
        Random random = new Random();
        for (int i = 0; i < 6;) {
            int redNumber = random.nextInt(33)+1;
            boolean flag = contains(number,redNumber);
            if (flag){
                number[i] = redNumber;
                i++;
            }
        }
        int blueNumber = random.nextInt(16)+1;
        number[6] = blueNumber;
        return number;
    }
    public static boolean contains(int number[],int redNumber){
        for (int i = 0; i < number.length; i++) {
            if (number[i] == redNumber){
                return false;
            }
        }
        return true;
    }
    public static int[] userInputNumber(){
        int userInputNumber[] = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6;) {
            System.out.println("请输入第"+ (i+1)+"个红球号码");
            int redNumber = sc.nextInt();
            if (redNumber>=0 && redNumber<=33){
                boolean flag = contains(userInputNumber,redNumber);
                if (flag){
                    userInputNumber[i] = redNumber;
                    i++;
                }
                else{
                    System.out.println("输入的红球重复了，请重新输入");
                }
            }
            else{
                System.out.println("输入的红球不合法，请重新输入");
            }
        }
        System.out.println("请输入蓝球号码");
        int blueNumber = sc.nextInt();
        if (blueNumber>=0&&blueNumber<=16){
            userInputNumber[userInputNumber.length-1] = blueNumber;
        }
        else{
            System.out.println("输入的蓝球不合法，请重新输入");
        }
        return userInputNumber;
    }
}
